import { prisma } from '@/lib/prisma'
import { NextResponse } from 'next/server'
import { hash } from 'bcryptjs'

export async function GET() {
  const users = await prisma.user.findMany({
    include: {
      role: true
    }
  })
  return NextResponse.json(users)
}

export async function POST(request: Request) {
  const { username, role, name, password } = await request.json()
  
  const hashedPassword = await hash(password, 10)

  const user = await prisma.user.create({
    data: {
      username,
      password: hashedPassword,
      name,
      role: {
        connect: { name: role }
      }
    },
    include: {
      role: true
    }
  })
  return NextResponse.json(user)
} 